pub resolve: &'a Resolve,
pub sources: &'a SourceMap<'b>,
pub compilation: Compilation,
+ pub env: &'a str,
- env: &'a str,
host: Layout,
target: Option<Layout>,
target_triple: String,
fn compile_custom(pkg: &Package, cmd: &str,
cx: &Context, first: bool) -> CargoResult<Work> {
+ let root = cx.get_package(cx.resolve.root());
+ let profile = root.get_manifest().get_targets().iter()
+ .find(|target| target.get_profile().get_env() == cx.env)
+ .map(|target| target.get_profile());
+ let profile = match profile {
+ Some(profile) => profile,
+ None => return Err(internal(format!("no profile for {}", cx.env)))
+ };
+
// TODO: this needs to be smarter about splitting
let mut cmd = cmd.split(' ');
// TODO: this shouldn't explicitly pass `KindTarget` for dest/deps_dir, we
let mut p = process(cmd.next().unwrap(), pkg, cx)
.env("OUT_DIR", Some(&output))
.env("DEPS_DIR", Some(&output))
- .env("TARGET", Some(cx.target_triple()));
+ .env("TARGET", Some(cx.target_triple()))
+ .env("DEBUG", Some(profile.get_debug().to_string()))
+ .env("OPT_LEVEL", Some(profile.get_opt_level().to_string()))
+ .env("PROFILE", Some(profile.get_env()));
for arg in cmd {
p = p.arg(arg);
}
directory in which all the output of the dependency's
build command was placed. This is useful for picking up
things like header files and such from other packages.
+* `CARGO_MANIFEST_DIR` - The directory containing the manifest for the package
+ being built.
+* `OPT_LEVEL`, `DEBUG` - values of the corresponding variables for the
+ profile currently being built.
+* `PROFILE` - name of the profile currently being built (see
+ [profiles][profile]).
+
+[profile]: manifest.html#the-[profile.*]-sections
# A complete example
use std::io::fs::PathExtensions;
fn main() {{
let _ncpus = os::getenv("NUM_JOBS").unwrap();
+ let debug = os::getenv("DEBUG").unwrap();
+ assert_eq!(debug.as_slice(), "true");
+
+ let opt = os::getenv("OPT_LEVEL").unwrap();
+ assert_eq!(opt.as_slice(), "0");
+
+ let opt = os::getenv("PROFILE").unwrap();
+ assert_eq!(opt.as_slice(), "compile");
+
let out = os::getenv("OUT_DIR").unwrap();
assert!(out.as_slice().starts_with(r"{0}"));
assert!(Path::new(out).is_dir());
let out = os::getenv("DEP_BAR_BAR_OUT_DIR").unwrap();
assert!(out.as_slice().starts_with(r"{0}"));
assert!(Path::new(out).is_dir());
+
+ let out = os::getenv("CARGO_MANIFEST_DIR").unwrap();
+ let p1 = Path::new(out);
+ let p2 = os::make_absolute(&Path::new(file!()).dir_path().dir_path());
+ assert!(p1 == p2, "{{}} != {{}}", p1.display(), p2.display());
}}
"#,
p.root().join("target").join("native").display()));